<template>


	<view>
		
	<view class="">
			<u-form :model="form" ref="uForm">
				<u-form-item label="手机" prop="phone">
					<u-input v-model="list.phone" />
				</u-form-item>
				<u-form-item label="密码" prop="password">
					<u-input v-model="list.password" />
				</u-form-item>
				
				<u-toast ref="uToast"></u-toast>
				<view class="u-demo-block">
					<text class="u-demo-block__title"></text>
					<view class="u-demo-block__content">
						<!-- <u-row customStyle="margin-bottom: 10px">
							<u-col span="8">
								<view class="demo-layout bg-purple-light">
									<u-form-item label="验证码" prop="Code">
										<u-input v-model="form.Code" />
									</u-form-item>
								</view>
							</u-col>
							<u-col span="4">
								<view class="demo-layout bg-purple">
									<u-button @click="verification_code" type="success">获取验证码</u-button>
								</view>
							</u-col>
						</u-row> -->
						<u-row customStyle="margin-bottom: 10px">
							<u-col span="4">
								<view class="demo-layout bg-purple"></view>
							</u-col>
							<u-col span="4">
								<view class="demo-layout bg-purple-light"></view>
							</u-col>
							<u-col span="4">
								<view class="demo-layout bg-purple-dark"></view>
							</u-col>
						</u-row>
						<u-row justify="space-between">
							<u-col span="4">
								<view class="demo-layout bg-purple">	<u-button @click="submit" type="primary">登录</u-button></view>
							</u-col>
							<u-col span="4">
								<view class="demo-layout bg-purple-light">	
								<u-button @click="mail_login" type="warning">切换邮箱登录</u-button></view>
							
							</u-col>
							<u-col span="4">
								<view class="demo-layout bg-purple">   	<u-button @click="register" type="success">注册</u-button></view>
							</u-col>
							
						</u-row>
					</view>
				</view>
		
			</u-form>

		
		</view>
	</view>
</template>

<script>
	
	import token from '@/common/token/token.js'
// import form from '../../uni_modules/uview-ui/libs/config/props/form';

export default {
	data() {
		return {
			form: {
				phone: '',
				password: '',
				Code:'',
			},
			list:{
				phone: '',
				password: ''
			},
			show: false,
			list1:{
					type: 'error',
					icon: false,
					title: '失败主题',
					message: "账号密码错误！",
					iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png'
					},
			rules: {
				phone: [
					{ 
						required: true, 
						
						// 可以单个或者同时写两个触发验证方式 
						
					}
				],
				password: [
					{
						min: 5, 
						message: '密码不能少于6个', 
						trigger: 'change'
					}
				]
			}
		};
	},
	methods: {
		submit() {
			// console.log(this.form);
			this.$api({
				method: 'post',
				url: '/system/login/login',
				 data: this.list
			}).then(res => {
				// uni.setStorageSync('token', res.data);
				console.log("----------------index"+token.id);
				if (res.data != null) {
					uni.reLaunch({
						url:"/pages/home/home",
						
					})
				} else {
						// console.log(res.data);
					this.showToast(this.list1),
					console.log("失败");
				}
				
			}).catch(err => {
				console.log(err)
			});
			
			
			
		
		
		},
		
		showToast(params) {
			console.log(params);
			this.$refs.uToast.show({
				...params,
				complete() {
					params.url && uni.navigateTo({
						url: params.url
					})
				}
			})
		},
		
		register(){
			uni.navigateTo({
				url:"/pages/index/register/register"
			})
		},
		mail_login(){
			uni.navigateTo({
				url:"/pages/index/email_login/email_login"
			})
		}
	},
	// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	}
};
</script>
<style>
/* 	.wrap {
	    padding: 12px;
	}
	
	.demo-layout {
	    height: 25px;
	    border-radius: 4px;
	}
	
	.bg-purple {
	    background: #ced7e1;
	}
	
	.bg-purple-light {
	    background: #e5e9f2;
	}
	
	.bg-purple-dark {
	    background: #99a9bf;
	} */
</style>
